package cn.dkk.behavior_design.meditor;

/**
 * @author dkk
 * @date 2022/7/29
 * @desc 中介者和观察者模式可以配合使用,以达到生产者生产消息时,中介者通知消费者消费的模式
 */
public class Test {
    public static void main(String[] args) {
        Mediator mediator = new Mediator();
        Consumer consumer = new Consumer(mediator);
        mediator.reg(consumer);
        Producer producer = new Producer(mediator);
        mediator.reg(producer);
        producer.sendMes("你好我是生产者1");
        producer.sendMes("你好我是生产者2");
        producer.sendMes("你好我是生产者3");
        consumer.getMes();
        consumer.getMes();
        // 此时队列中还有一条消息
        // consumer.getMes();
    }
}
